package com.my.study.init.log;

import cn.hutool.extra.spring.SpringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.core.annotation.Order;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

@Component
@Slf4j
@Order(1000)
public class AppStartLogEvent implements ApplicationListener<ApplicationReadyEvent> {

    @Override
    public void onApplicationEvent(ApplicationReadyEvent event) {
        // 打印第三方url等信息
        log.info("nacos user={}||pass={}||url:{}", "nacos", "nacos",
                "http://127.0.0.1:8848/nacos/#/configurationManagement?dataId=&group=&appName=&namespace=&pageSize=&pageNo=");
        log.info("sentinel user={}||pass={}||url:{}", "sentinel", "sentinel",
                "http://127.0.0.1:8080");
        log.info("xxl-job user={}||pass={}||url:{}", "admin", "123456",
                "http://127.0.0.1:9080/app-job-admin/toLogin");
        Environment environment = SpringUtil.getBean(Environment.class);
        boolean switchFlag = environment.getProperty("swagger.switch", Boolean.class, false);
        if(switchFlag){
            log.info("swagger url:{}", "http://localhost:"
                    + environment.getProperty("server.port")
                    + environment.getProperty("server.servlet.context-path")
                    + "/swagger-ui.html");
        }
    }
}
